const http = require('http')

const app = http.createServer()

app.on('request', (req, res) => {
    const url = req.url

    let content = "<h2>404 Not Found</h2>"

    if (url === '/' || url === '/index.html') {
        content = "<h2>首页</h2>"
    } else if (url === '/about.html') {
        content = "<h2>关于</h2>"
    } else if (url === '/news.html') {
        content = "<h2>新闻页面</h2>"
    }

    res.setHeader('Content-Type', 'text/html;charset=utf-8')

    res.end(content)
})

app.listen(3000, () => {
    console.log('服务器启动于: http://127.0.0.1:3000');
})